package com.server.rule.data.loader;


import java.util.Calendar;
import java.util.Map;

import com.shared.data.IData;
import com.shared.model.Assure;
import com.server.rule.data.Data;
import com.shared.rule.TypeDataRule;


public class AssureInformationLoader extends InformationLoader {

	
	
	public AssureInformationLoader() {
		super(new Assure());		
	}
	
	public AssureInformationLoader(IData object) {
		super(object);		
	}
		


	@Override
	public void loadInformation(Data data) throws IllegalArgumentException, IllegalAccessException{
		super.loadInformation(data);
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);	
		int yearNaissance = ((Assure) object).getDateNaissance().getAnnee();
		if(yearNaissance!=0){
			Integer diff = (year-yearNaissance);
			data.put(getClassName()+".age",diff.doubleValue(), false);
		}
		int yearPermis = ((Assure) object).getDatePermis().getAnnee();
		if(yearPermis!=0){
			Integer diff2 = (year-yearPermis);
			data.put(getClassName()+".anneedepermis",diff2.doubleValue(), false);
		}
		
		
	}

	
	public void loadInformationStructure(Data data) throws IllegalArgumentException, IllegalAccessException{
		super.loadInformationStructure(data);
		data.put(getClassName()+".age", (Double) null, false);	
		data.put(getClassName()+".anneedepermis",(Double) null, false);
	}
	
	public Map<String,TypeDataRule> getAvailableData() throws IllegalArgumentException, IllegalAccessException{
		Data dataTemp = new Data();
		this.loadInformationStructure(dataTemp);
		return dataTemp.getMapType();
	}
	
}
